<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title><{config_item('website_title')}></title>
    <meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <style>
        body {
            width: 100%;
            background: #eeeeee;
            color: #3e3e3e;
            font-family: "黑体", "微软雅黑", Arial, Helvetica, sans-serif;
        }

        .blank {
            width: 100%;
            height: 0.9rem;
        }

        a {
            text-decoration: none;
            color: #3e3e3e;
        }

        img {
            width: 100%;
            height: 100%;
            border: none;
        }

        .flexbox {
            display: box;
            display: -webkit-box;
            display: -moz-box;
            display: -ms-flexbox;
            display: -webkit-flex;
            display: flex;
            -webkit-box-align: center;
            -webkit-align-items: center;
            -moz-align-items: center;
            -ms-align-items: center;
            -o-align-items: center;
            align-items: center;
        }

        .wrap {
            width: 100%;
        }

        .commentListbox {
            box-sizing: border-box;
            padding: 0 0 0 0.2rem;
        }

        .commntwrap {
            position: relative;
            display: box;
            display: -webkit-box;
            display: -moz-box;
            display: -ms-flexbox;
            display: -webkit-flex;
            display: flex;
            box-sizing: border-box;
            padding: 0.2rem 0.2rem 0.2rem 0;
        }

        .listListL {
            position: relative;
            width: 1rem;
            height: 1rem;
            margin-right: 0.2rem;
        }

        .listUserL {
            -webkit-box-flex: 1;
            -moz-box-flex: 1;
            -webkit-flex: 1;
            -ms-flex: 1;
            flex: 1;
            font-size: 0.32rem;
        }

        .commemtListR {
            -webkit-box-flex: 1;
            -moz-box-flex: 1;
            -webkit-flex: 1;
            -ms-flex: 1;
            flex: 1;
        }

        .commentUserR {
            font-size: 0.22rem;
            color: #aaaaaa;
        }

        .listcon {
            font-size: 0.22rem;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        /*navbar*/
        .navbar {
            position: fixed;
            left: 0;
            bottom: 0;
            width: 100%;
            font-size: 0;
            background: #fff;
            height: 0.8rem;
            z-index: 100;
        }

        .navbar:before {
            content: " ";
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 1px;
            border-top: 1px solid #c5c5c5;
            -webkit-transform-origin: 0 0;
            transform-origin: 0 0;
            -webkit-transform: scaleY(0.5);
            transform: scaleY(0.5);
        }

        .navwrap {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            padding-top: 0.1rem;
        }

        .navbar_a {
            display: block;
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            -ms-flex: 1;
            flex: 1;
            padding: 0.1rem 0;
            color: #272636;
            -webkit-tap-highlight-color: transparent;
        }

        .navbar_imgbox {
            position: relative;
            margin: 0 auto;
            width: 0.30rem;
            height: 0.30rem;
        }

        .navbar_label {
            font-size: 0.20rem;
            margin-top: 0.06rem;
            text-align: center;
        }

        .navbarF {
            color: #ff5f1e;
        }

        /*navbar end*/
        #msg_count {
            position: absolute;
            background: #ff0000;
            color: #fff;
            width: 0.3rem;
            height: 0.3rem;
            border-radius: 50%;
            text-align: center;
            line-height: 0.3rem;
            right: -0.1rem;
            top: -0.1rem;
        }
    </style>
</head>
<body style="background:#fff;">
<!-- content start -->
<section class="wrap">
    <!-- start -->
    <div class="commentListbox" id="im_list">
        <!--联系人列表模板 start-->
        <script type='text/html' id='im_list_Template'>
            {{each cnts}}
            <a href="#" id="im_{{$value.uid |substring}}">
                <div class="commntwrap">
                    <div class="listListL">
                        <img id="headimgurl" src="/public/images/user_header.jpg">
                        <div id="msg_count" style="font-size: 0.26rem; "></div>
                    </div>
                    <div class="commemtListR ">
                        <div class="commentUser flexbox">
                            <div class="listUserL" id="full_name">

                            </div>
                            <div class="commentUserR">
                                {{$value.time | dateFormat}}
                            </div>
                        </div>
                        <div class="listcon">
                            {{if $value.uid==1}}图片{{else if $value.uid==2}}语音{{else}}{{$value.msg[0][1]}}{{/if}}
                        </div>
                    </div>
                </div>
            </a>
            {{/each}}
        </script>
        <!--联系人列表模板 end-->
    </div>
    <!-- end -->
</section>
<script type="text/javascript" src="/public/js/jquery.js"></script>
<script type="text/javascript" src="/public/js/layer/layer.js"></script>
<script type="text/javascript" src="/public/js/artTemplate.js"></script>
<script type="text/javascript" src="/views/default/skin/js/public.js"></script>
<{include file="default/footer.html"}>
<!-- IE8及以下支持JSON -->
<!--[if lt IE 9]>
<script src="https://g.alicdn.com/aliww/ww/json/json.js" charset="utf-8"></script>
<![endif]-->
<!-- WSDK-->
<script src="https://g.alicdn.com/aliww/h5.openim.sdk/1.0.6/scripts/wsdk.js"></script>
<script language="JavaScript">
    var sdk = new WSDK();

    sdk.Base.login({
        uid: '<{$member_data.uid}>',
        appkey: '<{config_item("im_appkey")}>',
        credential: '<{$member_data.uid}>',
        timeout: 4000,
        success: function (data) {
            //console.log('login success', data);
            get_contact();//获取最近联系人
        },
        error: function (error) {
            layer.msg('登录失败');
        }
    });

    //获取新消息
    function get_new_msg() {
        var recentTribe = [];
        sdk.Base.getUnreadMsgCount({
            count: 30,
            success: function (data) {
                console.log(data);
                var list = data.data;
                list.forEach(function (item) {
                    $('#im_' + item.contact.substring(8) + ' #msg_count').text(item.msgCount).show();
                });
            },
            error: function (error) {
                //console.log('获取未读消息的条数失败' ,error);
            }
        });
    }

    //获取最近用户列表
    function get_contact() {
        sdk.Base.getRecentContact({
            count: 30,
            success: function (data) {
                //console.log(data);
                data = data.data;
                //消息列表
                template.helper('dateFormat', function (time) {
                    var date = new Date(parseInt(time) * 1000);
                    var data = {
                        "M": date.getMonth() + 1, //月份
                        "d": date.getDate(), //日
                        "h": date.getHours(), //小时
                        "m": date.getMinutes(), //分
                        "s": date.getSeconds(), //秒
                    };
                    return data['M'] + '-' + data['d'] + ' ' + data['h'] + ':' + data['m'];
                });
                template.helper('substring', function (str) {
                    return str.substring(8);
                });
                //消息列表
                var html = template('im_list_Template', data);
                $('#im_list').html(html);
                //获取用户头像昵称
                var im_id = Array();
                $.each(data.cnts, function (index, content) {
                    im_id.push(content.uid.substring(8))
                })
                $.ajax({
                    url: '<{site_url("/web/im/user_info")}>',
                    data: {'im_id': im_id},
                    type: 'POST',
                    dataType: 'json',
                    success: function (user_data) {
                        $.each(user_data.result, function (i, c) {
                            $('#im_' + c.im + ' #headimgurl').attr('src', c.headimgurl);
                            $('#im_' + c.im + ' #full_name').text(c.full_name);
                            $('#im_' + c.im).attr('href', c.link);
                        })
                    }
                })
                //获取用户新消息数量
                get_new_msg();
                // setTimeout('get_contact()', 10000);
            },
            error: function (error) {
                layer.msg('没有获取到联系人列表');
            }
        });
    }
</script>
</body>
</html>




